package com.o2o.cleaning.month.platform.ebusiness_plat.rongegou

import com.alibaba.fastjson.{JSON, JSONObject}
import com.o2o.cleaning.month.platform.ebusiness_plat.rongegou.RongYiGou.{address, addressRongyigou}
import org.apache.spark.rdd.RDD
import org.apache.spark.sql.{DataFrame, SparkSession}
import org.elasticsearch.spark._

/**
  * @author: gaoyadi
  * @Date: 2018/12/18 15:18
  * @Description:
  * @Modify By:
  */
object RYG_error_deal {
  def main(args: Array[String]): Unit = {
    val spark = SparkSession.builder()
      .appName("SparkTest")
      .master("local[*]")
      .config("es.nodes", "192.168.1.29")
      .config("es.port", "9200")
      .config("es.net.http.auth.user", "elastic")
      .config("es.net.http.auth.pass", "changeme")
      .config("cluster.name","O2OElastic")
      .getOrCreate()
    val sc = spark.sparkContext
    val sqlcontext = spark.sqlContext

    sc.hadoopConfiguration.set("fs.s3a.access.key", "GAO7EO9FWKPJ8WFCQDME")
    sc.hadoopConfiguration.set("fs.s3a.secret.key", "LZ0xaHBSYKHaJ9ECDbX9f7zin79UZkXfGoNapRPL")
    sc.hadoopConfiguration.set("fs.s3a.endpoint", "https://obs.cn-north-1.myhuaweicloud.com")

    /***
      * 需要修改的参数信息
      */
    val clusterName="hdfs://192.168.2.188:9000"
    val year = "2020"
    var month="10"
    var platform="rongyigou"
    val index = s"${year}_${platform}/${platform}_${year}_${month}"

    /*val values: RDD[String] = sc.esJsonRDD(index).values

    spark.read.json(values).write.orc("s3a://o2o-dataproces-group/zsc/2020/10/rongyigou/good_addr_deal_sour/")*/

    val frame: DataFrame = spark.read.orc("s3a://o2o-dataproces-group/zsc/2020/10/rongyigou/good_addr_deal_sour/")
      .drop("administrative_region")
      .drop("city")
      .drop("city_grade")
      .drop("city_origin")
      .drop("district")
      .drop("district_origin")
      .drop("economic_division")
      .drop("if_city")
      .drop("if_district")
      .drop("if_state_level_new_areas")
      .drop("poor_counties")
      .drop("province")
      .drop("regional_ID")
      .drop("rural_demonstration_counties")
      .drop("rural_ecommerce")
      .drop("the_belt_and_road_city")
      .drop("the_belt_and_road_province")
      .drop("the_yangtze_river_economic_zone_city")
      .drop("the_yangtze_river_economic_zone_province")
      .drop("urban_agglomerations")
      .drop("name")
      .drop("address")
      .drop("aedzId")
      .drop("latitude")
      .drop("longitude")
      .drop("town")
      .drop("registration_institution")

    val frame1 = addressRongyigou(spark, frame, address)

    frame1.write.orc("s3a://o2o-dataproces-group/zsc/2020/10/rongyigou/good_addr_deal_result/")


    val value: RDD[JSONObject] = frame1.toJSON.rdd.map(lines => {
      val nObject: JSONObject = JSON.parseObject(lines)
      nObject
    })
    value.saveToEs(index, Map("es.mapping.id" -> "good_id"))


  }
}
